package appUtils;

import android.text.TextUtils;

/**
 * Created by lj on 2017/7/18 0018.
 */

public class HiddenRule {

    public HiddenRule() {
    }

    public String accountCommonHidden(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        try {
            String[] strarray = str.split("[@]");
            String front = strarray[0];
            front = nameHidden(front);
            String behind = strarray[1];
            str = front + "@" + behind;
        } catch (Exception e) {
            e.printStackTrace();
            return nameHidden(str);
        }
        return str;
    }

    public String nameHidden(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        try {
            switch (str.length()) {
                case 1:
                case 2:
                    str = str.substring(0, 1) + "*";
                    break;
                case 3:
                    str = str.substring(0, 1) + "*" + str.substring(str.length() - 1, str.length());
                    break;
                case 4:
                    str = str.substring(0, 1) + "**" + str.substring(str.length() - 1, str.length());
                    break;
                case 5:
                case 6:
                    str = str.substring(0, 2) + "**" + str.substring(str.length() - 2, str.length());
                    break;
                case 7:
                case 8:
                case 9:
                    str = str.substring(0, 3) + "***" + str.substring(str.length() - 3, str.length());
                    break;
                case 10:
                default:
                    str = str.substring(0, 4) + "****" + str.substring(str.length() - 4, str.length());
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
            PayTokenException.getInstance().saveExceptionFile("HiddenRule" +
                    " nameHidden error = " + e.getMessage());
            return "";
        }
        return str;
    }
}
